package com.framework.core.utils;

import java.util.Map;

import com.framework.core.domain.Control;
import com.framework.core.myexception.NoSuchUrlException;

//Properties工具
public class PropertiesUtils {

	private static PropertiesUtils mappingUtils;

	// properties map
	private static Map<String, Object> map;

	private PropertiesUtils() {

	}

	public synchronized static PropertiesUtils getInstance() {

		if (null == mappingUtils) {
			mappingUtils = new PropertiesUtils();
		}
		return mappingUtils;

	}

	public Map<String, Object> getMap() {
		return map;
	}

	public void setMap(Map<String, Object> map) {
		PropertiesUtils.map = map;
	}

	// 根据name获取对应属性
	public static String getPropertiesValueByName(String name) {
		if (map.containsKey(name)) {
			return map.get(name).toString();
		} else {
			System.out.println("不存在此属性！");
		}
		return null;
	}

	// 检查请求属性是否存在,用于xml解析请求，现在用注解
	public Control checkUrl(String name) {
		if (map.containsKey(name)) {
			return (Control) map.get(name);
		} else {
			throw new NoSuchUrlException("不存在此属性！");
		}
	}

}
